package cc.momas.mybatis.multidatasource.cihua;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.CommandLineRunner;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * @author Sod-Momas
 * @since 2019.11.04
 **/
public class TestCiHuaClass implements CommandLineRunner {

    @Autowired
    private DataSource dataSource;

    @Override
    public void run(String... args) throws Exception {
        System.out.println("cihua ==== start");
//        System.out.println(dataSource);
        Connection connection = dataSource.getConnection();
        PreparedStatement ps = connection.prepareStatement("select id, title, update_time, author_name, tag from t_article;;");
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            System.out.println(rs.getInt("id"));
            System.out.println(rs.getString("title"));
            System.out.println(rs.getDate("update_time").toLocalDate());
            System.out.println(rs.getString("author_name"));
            System.out.println(rs.getString("tag"));
        }
        rs.close();
        ps.close();
        connection.close();
        System.out.println("cihua ==== end");
    }
}
